package com.ucar.train.service.impl;

import com.ucar.train.dao.GroupMapper;
import com.ucar.train.dao.UserGroupMapper;
import com.ucar.train.dao.UserRoleMapper;
import com.ucar.train.dto.Group;
import com.ucar.train.dto.UserGroup;
import com.ucar.train.dto.UserRole;
import com.ucar.train.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wufuqiang
 * @title: GroupServiceImpl
 * @projectName:train-parent
 * @description: T0D0
 * @created 2019-07-24 17:03
 */
@Service
public class GroupServiceImpl implements GroupService {

    @Autowired
    GroupMapper groupMapper;

    @Autowired
    UserGroupMapper userGroupMapper;

    @Autowired
    UserRoleMapper userRoleMapper;

    @Override
    public Integer saveGroup(Group group) {
        return groupMapper.saveGroup(group);
    }

    @Override
    public Integer updateGroup(Group group) {
        return groupMapper.updateGroup(group);
    }

    @Override
    public Group getGroup(Long id) {
        return groupMapper.getGroup(id);
    }

    @Override
    public List<Group> listGroups() {
        return groupMapper.listGroups();
    }

    @Override
    public Integer deleteGroup(Long id){
        groupMapper.deleteGroup(id);//删除组基本信息
        userGroupMapper.deleteUserGroupsByGroupId(id);//删除该组所有用户组信息
        return null;
    }

    @Override
    public Integer saveUserGroup(UserGroup userGroup) {
        System.out.println("打印打印打印"+userGroup);
        return userGroupMapper.saveUserGroup(userGroup);
    }

    @Override
    public Integer deleteUserGroup(Long id) {

        return userGroupMapper.deleteUserGroup(id);
    }

    @Override
    public List<UserGroup> listUserGroups() {
        return  userGroupMapper.listUserGroups();
    }

    @Override
    public Integer saveUserRole(UserRole userRole) {
        return userRoleMapper.saveUserRole(userRole);
    }

    @Override
    public Integer deleteUserRole(Long id) {
        return userRoleMapper.deleteUserRole(id);
    }

    @Override
    public Integer updateUserRole(UserRole userRole) {
        return userRoleMapper.updateUserRole(userRole);
    }

    @Override
    public UserRole getUserRole(Long id) {
        return userRoleMapper.getUserRole(id);
    }

    @Override
    public List<UserRole> listUserRoles() {
        System.out.println("listUserRoles查询结果：" + userRoleMapper.listUserRoles());
        return userRoleMapper.listUserRoles();
    }

    @Override
    public List<UserRole> listUserRolesByGroup(Long id) {
        return userRoleMapper.listUserRolesByGroup(id);
    }
}
